package com.pshcp.patient.tool;

import com.external.ws.soap.entity.dto.FeesListDTO;
import com.external.ws.soap.entity.dto.HosFeeViewDTO;
import com.external.ws.soap.entity.dto.OutFeeViewDTO;
import com.external.ws.soap.entity.res.HosFeeViewRes;
import com.external.ws.soap.entity.res.OutFeeViewRes;
import com.framework.base.TwoDTO;
import com.framework.tool.CommonTool;
import com.pshcp.common.enums.FeeTypeEnum;
import com.pshcp.domain.model.Patient;
import com.pshcp.patient.domain.searchfee.ao.FeeListAO;
import com.pshcp.patient.domain.searchfee.ao.HosFeeDetailAO;
import com.pshcp.patient.domain.searchfee.ao.OutFeeDetailAO;
import com.pshcp.patient.domain.searchfee.vo.HosFeeDetailItemVO;
import com.pshcp.patient.domain.searchfee.vo.HosFeeDetailVO;
import com.pshcp.patient.domain.searchfee.vo.OutFeeDetailItemVO;
import com.pshcp.patient.domain.searchfee.vo.OutFeeDetailVO;
import com.pshcp.patient.domain.searchfee.vo.PatFeeVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class SearchFeeTools {

    /**
     * 费用列表AO 转 ws dto
     * @param listAO
     * @return
     */
    public static FeesListDTO buildFeeListAO2WsDTO(FeeListAO listAO, String hisPatientId){
        FeesListDTO dto = new FeesListDTO();
        dto.setFeeType(listAO.getFeeType());
        dto.setAccessPatId(hisPatientId);
        TwoDTO<String, String> startEndTime = PatientCommonTools.buildStartEndTime(listAO.getSearchTime());
        dto.setStartDate(startEndTime.getOne());
        dto.setEndDate(startEndTime.getTwo());
        return dto;
    }

    public static OutFeeViewDTO buildOutFee(OutFeeDetailAO detailAO, Patient patient){
        OutFeeViewDTO outFeeViewDTO = new OutFeeViewDTO();
        outFeeViewDTO.setFeeId(detailAO.getFeeId());
        outFeeViewDTO.setAccessPatId(patient.getHisPatientId());
        return outFeeViewDTO;
    }

    public static OutFeeDetailVO buildWsOutFeeDetail2VO(OutFeeViewRes viewRes){
        OutFeeDetailVO outFeeDetailVO = CommonTool.copyProperties(viewRes, OutFeeDetailVO.class);
        outFeeDetailVO.setItems(CommonTool.copyPropertiesList(viewRes.getItems(), OutFeeDetailItemVO.class));
        return outFeeDetailVO;
    }

    public static HosFeeViewDTO buildHosFee(HosFeeDetailAO detailAO, Patient patient){
        HosFeeViewDTO hosFeeViewDTO = new HosFeeViewDTO();
        hosFeeViewDTO.setFeeId(detailAO.getFeeId());
        hosFeeViewDTO.setAccessPatId(patient.getHisPatientId());
        return hosFeeViewDTO;
    }

    public static HosFeeDetailVO buildWsHosFeeDetail2VO(HosFeeViewRes viewRes){
        HosFeeDetailVO hosFeeDetailVO = CommonTool.copyProperties(viewRes, HosFeeDetailVO.class);
        hosFeeDetailVO.setItems(CommonTool.copyPropertiesList(viewRes.getItems(), HosFeeDetailItemVO.class));
        return hosFeeDetailVO;
    }

    public static OutFeeDetailVO buildOutFeeDetailTestData(){
        OutFeeDetailVO detailVO = new OutFeeDetailVO();
        detailVO.setDeptName("住院一部3床");
        detailVO.setFeeName("住院费用");
        detailVO.setFeeId("2");
        detailVO.setDocName("王医生");
        detailVO.setPayTime("2022-11-10");
        detailVO.setPatName("王晓晓");

        OutFeeDetailItemVO outFeeDetailItemVO = new OutFeeDetailItemVO();
        outFeeDetailItemVO.setItemName("药水费");
        outFeeDetailItemVO.setItemNum("2");
        outFeeDetailItemVO.setItemPrice(new BigDecimal(10));
        outFeeDetailItemVO.setItemUnitPrice(new BigDecimal(20));

        OutFeeDetailItemVO outFeeDetailItemVO1 = new OutFeeDetailItemVO();
        outFeeDetailItemVO1.setItemName("注射费");
        outFeeDetailItemVO1.setItemNum("1");
        outFeeDetailItemVO1.setItemPrice(new BigDecimal(10));
        outFeeDetailItemVO1.setItemUnitPrice(new BigDecimal(10));

        List<OutFeeDetailItemVO> itemVOS = new ArrayList<>();
        itemVOS.add(outFeeDetailItemVO);
        itemVOS.add(outFeeDetailItemVO1);
        detailVO.setItems(itemVOS);
        return detailVO;
    }

    public static HosFeeDetailVO buildHosFeeDetailTestData(){
        HosFeeDetailVO detailVO = new HosFeeDetailVO();
        detailVO.setDeptName("住院一部3床");
        detailVO.setFeeName("住院费用");
        detailVO.setFeeId("2");
        detailVO.setDocName("王医生");
        detailVO.setPayTime("2022-11-10");
        detailVO.setPatName("王晓晓");

        HosFeeDetailItemVO outFeeDetailItemVO = new HosFeeDetailItemVO();
        outFeeDetailItemVO.setItemName("药水费");
        outFeeDetailItemVO.setItemNum("2");
        outFeeDetailItemVO.setItemPrice(new BigDecimal(10));
        outFeeDetailItemVO.setItemUnitPrice(new BigDecimal(20));

        HosFeeDetailItemVO outFeeDetailItemVO1 = new HosFeeDetailItemVO();
        outFeeDetailItemVO1.setItemName("注射费");
        outFeeDetailItemVO1.setItemNum("1");
        outFeeDetailItemVO1.setItemPrice(new BigDecimal(10));
        outFeeDetailItemVO1.setItemUnitPrice(new BigDecimal(10));

        List<HosFeeDetailItemVO> itemVOS = new ArrayList<>();
        itemVOS.add(outFeeDetailItemVO);
        itemVOS.add(outFeeDetailItemVO1);
        detailVO.setItems(itemVOS);
        return detailVO;
    }

    /**
     * TODO
     * @param feeType
     * @return
     */
    public static List<PatFeeVO> buildTestData(Integer feeType){

        PatFeeVO feeVO = new PatFeeVO();
        feeVO.setFeeId("1");
        feeVO.setFeeType(1);
        feeVO.setFeeName("核酸采样");
        feeVO.setDeptName("核酸采样门诊");
        feeVO.setDocName("王医生");
        feeVO.setTotalCost(new BigDecimal(30));

        PatFeeVO feeVO1 = new PatFeeVO();
        feeVO1.setFeeId("2");
        feeVO1.setFeeType(2);
        feeVO1.setFeeName("住院费用");
        feeVO1.setDeptName("住院一部3床");
        feeVO1.setDocName("王医生");
        feeVO1.setTotalCost(new BigDecimal(30));

        List<PatFeeVO> patFeeVOS = new ArrayList<>();
        if(FeeTypeEnum.OUT.getCode().intValue() == feeType){
            patFeeVOS.add(feeVO);
        }
        if(FeeTypeEnum.HOS.getCode().intValue() == feeType){
            patFeeVOS.add(feeVO1);
        }
        return patFeeVOS;
    }

}
